//
//  QLPersonalInfoEditVC.m
//  神约
//
//  Created by qlwl on 17/2/20.
//  Copyright © 2017年 qlwl. All rights reserved.
//

#import "QLPersonalInfoEditVC.h"
#import "QLPersonalInfoEditCell.h"
#import "QLPersonalEditNickVC.h"
#import "QLDatePickerView.h"
#import "QLPersonalEditSignVC.h"
#import "AddressPicker.h"
#import "QLPersonalEditOpinionVC.h"

@interface QLPersonalInfoEditVC ()<UITableViewDelegate,UITableViewDataSource,PickerViewDataSource, PickerViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) QLDatePickerView * datePicker ; //
@property (nonatomic, strong) AddressPicker * incomePicker ; //
@property (nonatomic, strong) AddressPicker * heightPicker ; //
@property (nonatomic, strong) AddressPicker * weightPicker ; //
@property (nonatomic, strong) AddressPicker * emotPicker;

@end

@implementation QLPersonalInfoEditVC
{
    NSArray * _incomeArray;
    NSArray * _heightArray;
    NSArray * _weightArray;
    NSArray * _emotArray;
    
    NSInteger _incomeRow;
    NSInteger _heightRow;
    NSInteger _weightRow;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _incomeArray = @[@"暂无收入",@"1000~2000",@"2000~3000",@"3000~5000",@"5000~8000",@"8000~10000",@"10000以上"];
    _heightArray = @[@"120cm以下",@"120~130 cm",@"130~140 cm",@"140~150 cm",@"150~160 cm",@"160~170 cm",@"170~180 cm",@"180~190 cm",@"190~200 cm",@"200cm以上"];
    _weightArray = @[@"30kg以下",@"30~40 kg",@"40~50 kg",@"50~60 kg",@"60~70 kg",@"70~80 kg",@"80~90 kg",@"90~100 kg",@"100kg以上"];
    _emotArray = @[@"未婚",@"已婚",@"离异"];
}


#pragma mark TabDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 4;
    }else if (section == 1){
        return 6;
    }else if (section == 2){
        return 1;
    }else{
        return 1;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 2) {
        QLPersonalInfoEditCell2 * cell = [tableView dequeueReusableCellWithIdentifier:@"QLPersonalInfoEditCell2"];
        cell.titLab.text = @"擅长的技能";
        cell.itemArray = nil;
        return cell;
    }else{
        QLPersonalInfoEditCell * cell = [tableView dequeueReusableCellWithIdentifier:@"QLPersonalInfoEditCell"];
        if (indexPath.section == 0) {
            NSArray * array = @[@"昵称",@"年龄",@"所在地区",@"个性签名"];
            cell.titLab.text = array[indexPath.row];
        }else if (indexPath.section == 1){
            NSArray * array = @[@"职业",@"收入",@"身高",@"体重",@"感情状况",@"对另一半的看法"];
            cell.titLab.text = array[indexPath.row];
        }else{
            NSArray * array = @[@"想学的技能"];
            cell.titLab.text = array[indexPath.row];
        }
        cell.contentLab.text = nil;
        return cell;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 2) {
        return 44;
    }else{
        return 44;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            QLPersonalEditNickVC * nickVC = [NSString instantiateViewControllerWithIdentifier:@"QLPersonalEditNickVC" andSBName:@"Mine"];
            nickVC.saveNickName = ^(NSString * nickName){
                
            };
            [self.navigationController pushViewController:nickVC animated:YES];
        }else if (indexPath.row == 1){
            [self.datePicker showInWindow];
        }else if (indexPath.row == 2){
            
        }else if (indexPath.row == 3){
            QLPersonalEditSignVC * signVC = [NSString instantiateViewControllerWithIdentifier:@"QLPersonalEditSignVC" andSBName:@"Mine"];
            signVC.saveSignName = ^(NSString * signName){
                
            };
            [self.navigationController pushViewController:signVC animated:YES];
        }
    }else if (indexPath.section == 1){
        if (indexPath.row == 0) {
            
        }else if (indexPath.row == 1){
            [self.incomePicker showInView:self.view];
        }else if (indexPath.row == 2){
            [self.heightPicker showInView:self.view];
        }else if (indexPath.row == 3){
            [self.weightPicker showInView:self.view];
        }else if (indexPath.row == 4){
            [self.emotPicker showInView:self.view];
        }else if (indexPath.row == 5){
            QLPersonalEditOpinionVC * opinionVC = [NSString instantiateViewControllerWithIdentifier:@"QLPersonalEditOpinionVC" andSBName:@"Mine"];
            opinionVC.saveOpinion = ^(NSString * opinion){
                
            };
            [self.navigationController pushViewController:opinionVC animated:YES];
        }
    }else if (indexPath.section == 2){
    
    }else if (indexPath.section == 3){
        
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 6;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 1;
}

#pragma mark property
- (QLDatePickerView *)datePicker
{
    if (!_datePicker) {
        _datePicker = [QLDatePickerView DatePickerView];
        _datePicker.title = @"选择生日";
        _datePicker.datePickerMode = UIDatePickerModeDate;
        _datePicker.maximumDate = [NSDate date];
        typeof(self)t_self = self;
        _datePicker.finishBtnClick = ^(NSDate *date){
            
        };
    }
    return _datePicker;
}

- (AddressPicker *)incomePicker
{
    if (!_incomePicker) {
        _incomePicker = [AddressPicker addressPickerView];
        _incomePicker.delegate = self;
        _incomePicker.dataSource = self;
        _incomePicker.isLoding = NO;
        [_incomePicker setTopHeadColor:NavBarTintColor];
        [_incomePicker setTopTitle:@"选择收入"];
        [_incomePicker setTopTitleColor:[UIColor whiteColor]];
        [_incomePicker setSureOrCancelBtnColor:[UIColor whiteColor]];
        _incomePicker.bgColor = [UIColor clearColor];
        typeof(self) weakSelf = self;
        _incomePicker.sureBtnClick = ^{
            NSInteger row = [weakSelf.incomePicker selectedRowInComponent:0];
            
        };
    }
    return _incomePicker;
}

- (AddressPicker *)heightPicker
{
    if (!_heightPicker) {
        _heightPicker = [AddressPicker addressPickerView];
        _heightPicker.delegate = self;
        _heightPicker.dataSource = self;
        _heightPicker.isLoding = NO;
        [_heightPicker setTopHeadColor:NavBarTintColor];
        [_heightPicker setTopTitle:@"选择身高"];
        [_heightPicker setTopTitleColor:[UIColor whiteColor]];
        [_heightPicker setSureOrCancelBtnColor:[UIColor whiteColor]];
        _heightPicker.bgColor = [UIColor clearColor];
        typeof(self) weakSelf = self;
        _heightPicker.sureBtnClick = ^{
            
        };
    }
    return _heightPicker;
}
- (AddressPicker *)weightPicker
{
    if (!_weightPicker) {
        _weightPicker = [AddressPicker addressPickerView];
        _weightPicker.delegate = self;
        _weightPicker.dataSource = self;
        _weightPicker.isLoding = NO;
        [_weightPicker setTopHeadColor:NavBarTintColor];
        [_weightPicker setTopTitle:@"选择重量"];
        [_weightPicker setTopTitleColor:[UIColor whiteColor]];
        [_weightPicker setSureOrCancelBtnColor:[UIColor whiteColor]];
        _weightPicker.bgColor = [UIColor clearColor];
        typeof(self) weakSelf = self;
        _weightPicker.sureBtnClick = ^{
        
        };
    }
    return _weightPicker;
}
- (AddressPicker *)emotPicker
{
    if (!_emotPicker) {
        _emotPicker = [AddressPicker addressPickerView];
        _emotPicker.delegate = self;
        _emotPicker.dataSource = self;
        _emotPicker.isLoding = NO;
        [_emotPicker setTopHeadColor:NavBarTintColor];
        [_emotPicker setTopTitle:@"感情状况"];
        [_emotPicker setTopTitleColor:[UIColor whiteColor]];
        [_emotPicker setSureOrCancelBtnColor:[UIColor whiteColor]];
        _emotPicker.bgColor = [UIColor clearColor];
        typeof(self) weakSelf = self;
        _emotPicker.sureBtnClick = ^{
            
        };
    }
    return _emotPicker;
}

#pragma mark AddressPicker delegate

- (NSInteger)numberOfComponentsInPickerView:(AddressPicker *)pickerView
{
    return 1;
}
- (NSInteger)pickerView:(AddressPicker *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (pickerView == _incomePicker) {
        return _incomeArray.count;
    }else if (pickerView == _heightPicker){
        return _heightArray.count;
    }else if (pickerView == _weightPicker){
        return _weightArray.count;
    }else if (pickerView == _emotPicker){
        return _emotArray.count;
    }
    return 0;
}
- (nullable NSString *)pickerView:(AddressPicker *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component __TVOS_PROHIBITED
{
    if (pickerView == _incomePicker) {
        return _incomeArray[row];
    }else if (pickerView == _heightPicker){
        return _heightArray[row];
    }else if (pickerView == _weightPicker){
        return _weightArray[row];
    }else if (pickerView == _emotPicker){
        return _emotArray[row];
    }
    return nil;
}
- (void)pickerView:(AddressPicker *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    
}

- (UIView *)pickerView:(AddressPicker *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(nullable UIView *)view
{
    UILabel* pickerLabel = (UILabel*)view;
    if (!pickerLabel){
        pickerLabel = [[UILabel alloc] init];
        pickerLabel.adjustsFontSizeToFitWidth = YES;
        [pickerLabel setTextAlignment:NSTextAlignmentCenter];
        [pickerLabel setBackgroundColor:[UIColor clearColor]];
        [pickerLabel setFont:[UIFont boldSystemFontOfSize:17]];
    }
    pickerLabel.text=[self pickerView:pickerView titleForRow:row forComponent:component];
    return pickerLabel;
}



@end
